package algorithm.R;

import java.util.Random;

import algorithm.ValueFactory;

public class RandomStringFactory extends ValueFactory {
	Object[] stringvalues;
	final static int MAX=(int) (Math.pow(2,31)-1);
	public RandomStringFactory(int tcNum) {
		super(tcNum);
		stringvalues=new Object[tcNum];
	}

	@Override
	public Object[] getValue(Object min, Object max) {
		int minlength=(Integer)min;
		int maxlength=(Integer)max;
		Random random=new Random();
		
		if(minlength==maxlength)
		{
			minlength=0;
			maxlength=MAX-1;
		}
		if(minlength<0) minlength=0;
		if(maxlength>=MAX) maxlength=MAX-1;
		
		for(int i=0;i<stringvalues.length;i++)
		{
			
			int stringLength=random.nextInt(maxlength+1);
			stringvalues[i]=getRandomString(stringLength);
		}
		// TODO Auto-generated method stub
		return stringvalues;
	}
public static String getRandomString(int length) {   
	String base = " 	!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_'abcdefghijklmnopqrstuvwxyz{|}~";   
	Random random = new Random();   
	StringBuffer sb = new StringBuffer();   
	for (int i = 0; i < length; i++) {   
	      int number = random.nextInt(base.length());   
	      sb.append(base.charAt(number));   
    }   
       return sb.toString();    
	}

@Override
public void addTC(Object newTC) {
	// TODO Auto-generated method stub
	
}

@Override
public double[] getDistance(Object candi) {
	// TODO Auto-generated method stub
	return null;
}   

}
